package com.ghl.springbootmysqlmasterslave.datasource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * 动态数据源.数据源路由,实现动态切换
 */
public class DynamicDataSource extends AbstractRoutingDataSource {

    private static final Logger logger = LoggerFactory.getLogger(DynamicDataSource.class);

    @Override
    protected Object determineCurrentLookupKey() {
        DBTypeEnum dbTypeEnum = DBContextHolder.get();
        logger.info("当前数据源为{}", DBContextHolder.get());
        return DBContextHolder.get();
    }
}
